﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

using Gift.Model;
using Gift.DAL;
using Gift.Model.ENUM;

namespace WebSite.admin.admin
{
    public partial class roleManager : BaseAdmin
    {
        readonly dalRole theRole = new dalRole();
        tbRole oRole;
        // Methods
        private void DeletedAdmin()
        {

            if ((base.Request.QueryString["rid"] != null) && (base.Request.QueryString["action"] != null))
            {
                oRole = theRole.GetModel(int.Parse(base.Request.QueryString["rid"].ToString()));
                oRole.IsDeleted = true;
                theRole.Update(oRole);
                ExtAspNet.Alert.Show("删除管理员成功！");
                this.BindGrid();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(ERule.RoleManager);
                this.DeletedAdmin();
                this.BindGrid();
            }
        }


        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }

        string GetSqlWhere
        {
            get
            {
                StringBuilder strWhere = new StringBuilder();


                if (this.txtKeywords.Text.Trim() != "")
                {
                    strWhere.AppendFormat(" RoleName like '%{0}%' or Remark like '%{0}%'", this.txtKeywords.Text.Trim());
                }
                return strWhere.ToString();
            }
        }


        protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            DataTable table = theRole.GetList(GetSqlWhere).Tables[0];
            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);
            Grid1.DataSource = view1;
            Grid1.DataBind();
        }
        private void BindGrid()
        {
            DataTable table = theRole.GetList(GetSqlWhere).Tables[0];

            Grid1.DataSource = table;
            Grid1.DataBind();


        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindGrid();
        }

    }
}